<template>
  <el-tooltip
    effect="dark"
    placement="bottom"
    popper-class="popper-tooltip"
    :teleported="false"
    :disabled="props.conifgId ? false : true"
  >
    <SvgIcon icon-class="下载" v-if="props.conifgId" />
    <SvgIcon icon-class="ic_禁用" v-else />
    <template #content>
      <div class="download-btn" @click="downLoad('二次开发')">二次开发</div>
      <div class="download-btn" @click="downLoad('离线部署')">离线部署</div>
    </template>
  </el-tooltip>
</template>
<script setup lang="ts">
import api from '@/api';
import { loadingResources } from '@/utils/download-package';
import { useRequest } from '@jl/common/composable';
import { ElMessage } from 'element-plus';
import { debounce } from 'lodash';

interface IProps {
  activityId: string;
  conifgId: string;
}

const props = withDefaults(defineProps<IProps>(), {
  activityId: '',
  conifgId: '',
});

const { run: getSceneDetail, data: sceneDetail } = useRequest<any, API.Scene.Scene | null>(
  api.scene.getSceneDetail,
  null
);

//下载资源
const downTypeText = ref('');
const downLoad = debounce(async (type: string) => {
  //获取资源详情
  downTypeText.value = type;
  await getSceneDetail({ params: { activityId: props?.activityId } });
  await loadingResources(sceneDetail.value, type, downCallBack);
});

const downCallBack = (result: any) => {
  if (result) {
    ElMessage({
      type: 'warning',
      message: `正在生成${downTypeText.value}包，请到【下载管理】里面查看`,
      customClass: 'warning-style',
    });
  }
};
</script>
<style lang="less" scoped>
.svg-icon {
  font-size: 36px;
}
</style>
